package com.song.druid.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.song.druid.annotation.EnableSensitive;
import com.song.druid.entity.UserInfo;
import com.song.druid.mapper.UserInfoMapper;
import com.song.druid.model.PageInfo;
import com.song.druid.param.UserQueryParam;
import com.song.druid.service.UserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户信息 服务实现类
 * </p>
 *
 * @author song
 * @since 2023-11-09
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @EnableSensitive
    @Override
    public boolean saveSensitive(UserInfo userInfo) {
        return save(userInfo);
    }

    @EnableSensitive
    @Override
    public boolean saveBatchSensitive(List<UserInfo> userInfos) {
        return saveBatch(userInfos);
    }

    @EnableSensitive
    @Override
    public boolean updateByIdSensitive(UserInfo userInfo) {
        return updateById(userInfo);
    }

    @EnableSensitive
    @Override
    public boolean updateBatchByIdSensitive(List<UserInfo> userInfos) {
        return updateBatchById(userInfos);
    }

    @Override
    public PageInfo queryPage(UserQueryParam userQueryParam) {
        Page<UserInfo> result = PageHelper.startPage(userQueryParam.getPageNum(), userQueryParam.getPageSize())
                .doSelectPage(() -> baseMapper.queryList(userQueryParam));
        return PageInfo.transfer(result);
    }
}
